package com.wxlsoft.config.model;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class EsbCheckService {

	private String id;
	
	private String saveType;
	
	private String status;
	
	private String cpstatus;
	
	public static EsbCheckService parse(JsonNode data) {
		boolean exists = data.get("total").asInt() >= 1;
		String id = exists ? ((ArrayNode) data.get("records")).get(0).get("id").asText() : "";
		String saveType = exists ? "update" : "save";
		String status = exists ? "register" : "unregister";
		String cpstatus = exists ? "修改" : "未下发";
		return new EsbCheckService(id, saveType, status, cpstatus);
	}
	
	public static EsbCheckService definedParse(JsonNode data) {
		boolean exists = data.get("total").asInt() >= 1;
		String id = exists ? ((ArrayNode) data.get("records")).get(0).get("eid").asText() : "";
		String saveType = exists ? "update" : "save";
		return new EsbCheckService(id, saveType, null, null);
	}	

}
